package com.dyw.Day03;

/**
 * @author Devil
 * @create 2022-01-09-23:52
 */

/**
 *
 * 移动0
 * 思路将第i个非0元素放到第i个位置上
 */
public class Demo01 {
    public static void main(String[] args) {
        int[] ints = {0,1,0,1};
        new Demo01().moveZeroes(ints);
    }
    public void moveZeroes(int[] nums) {
        int n = nums.length, left = 0, right = 0;
        while (right < n) {
            if (nums[right] != 0) {
                swap(nums, left, right);
                left++;
            }
            right++;
        }
    }

    public void swap(int[] nums, int left, int right) {
        int temp = nums[left];
        nums[left] = nums[right];
        nums[right] = temp;
    }
}

